Page({
  data: {
    label: '',
    labels: [],
    theme: 'light',
  },
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('init', ({value}) => {
      this.setData({ labels: [...value] })
    })

    this.setData({
      theme: wx.getSystemInfoSync().theme || 'light'
    })

    if (wx.onThemeChange) {
      wx.onThemeChange(({theme}) => {
        this.setData({theme})
      })
    }
  },
  addLabel(e) {
    const { label, labels } = this.data
    if (labels.includes(label)) return
    this.setData({
      labels: [...labels, label]
    })
  },
  closeLabel(e) {
    console.log(222,e);
    const { index } = e.target.dataset
    const { labels } = this.data
    labels.splice(index, 1)
    this.setData({
      labels: [...labels]
    })
  },
  back() {
    wx.navigateBack()
  },
  onSubmit(e) {
    this.getOpenerEventChannel().emit('submit', this.data.labels)
    this.back()
  },
  onShareAppMessage() {
    return {
      title: '东鸣西应',
      path: '/page/home/index'
    }
  },
})
